<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">设置菜单</h4>
</div>
<div class="modal-body">
    <form>
        <div class="form-group">
            <input type="text" id="menu-name" class="form-control" placeholder="Menu Name"
                   value="{% if current_menu %}{{ current_menu.title }}{% endif %}">
        </div>
        <div class="form-group">
            <input type="text" id="menu-code" class="form-control" placeholder="Menu Code"
                   value="{% if current_menu %}{{ current_menu.code }}{% endif %}">
        </div>
        <div class="form-group">
            <input type="text" id="menu-link-url" class="form-control" placeholder="Link URL"
                   value="{% if current_menu %}{{ current_menu.link_url }}{% endif %}">
        </div>
        <div class="form-group">
            <input type="number" id="menu-position" class="form-control" placeholder="Menu Position"
                   value="{% if current_menu %}{{ current_menu.position }}{% endif %}">
        </div>
        <div class="form-group">
            <input type="text" id="menu-icon-class" class="form-control" placeholder="Menu Icon Class"
                   value="{% if current_menu %}{{ current_menu.icon_class }}{% endif %}">
        </div>
        <div class="form-group">
            <select id="menu-is-admin" class="form-control" title="是否为管理员菜单?">
                <option value="1" {% if current_menu and current_menu.is_admin %}selected{% endif %}>是</option>
                <option value="0" {% if current_menu and not current_menu.is_admin %}selected{% endif %}>否</option>
            </select>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">我再想想</button>
    <button type="button" class="btn my-btn-primary edit-menu-btn">确认并保存</button>
</div>
<script>
    $('.edit-menu-btn').click(function () {
        var menu_name = $('#menu-name').val();
        var menu_link_url = $('#menu-link-url').val();
        var menu_position = $('#menu-position').val();
        var menu_code = $('#menu-code').val();
        var menu_is_admin = $('#menu-is-admin').val();
        var menu_icon_class = $('#menu-icon-class').val();
        if (menu_name && menu_code && menu_link_url) {
            var url = {% if current_menu %}'{{ url_for('menu.menu_edit', menu_id=current_menu.id) }}'{% else %}'{{ url_for('menu.menu_create') }}'{% endif %};
            var data = {
                'menu_name': menu_name,
                'menu_code': menu_code,
                'menu_position': menu_position,
                'menu_link_url': menu_link_url,
                'menu_is_admin': menu_is_admin,
                'menu_icon_class': menu_icon_class
            };
            $.post(url, data, function (data, status) {
                window.location.reload();
            });
        } else {
            console.log('error');
            return false;
        }
    });
</script>